﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SharingCenter.Web.User.CurrentProfile
{
    using SharingCenter.Web.Classes;
    using SharingCenter.Web.Classes.enums;
    using SharingCenter.Web.Classes.Profiles;
    using System.Runtime.Serialization.Json;
    using System.IO;
    using System.Text;

    public partial class Contact : PageBase
    {

        protected void Page_Init(object sender, EventArgs e)
        {
            FormView1.ItemUpdating += new FormViewUpdateEventHandler(FormView1_ItemUpdating);
            FormView1.ItemUpdated += new FormViewUpdatedEventHandler(FormView1_ItemUpdated);
            LinqDataSource1.Selected += new EventHandler<LinqDataSourceStatusEventArgs>(LinqDataSource1_Selected);
            using (scDataContext cxt = new scDataContext())
            {
                Sc_Address adr = cxt.Sc_Addresses.SingleOrDefault(d => d.UserId == Profile.UserId);
                if (null == adr)
                {
                    ProfileOperations.AddNewAddress(Profile.UserId);
                }
            }
        }

        void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
        {
            if (e.Exception == null)
            {
                PrivacyDropDownList pl = (PrivacyDropDownList)FormView1.FindControl("addrPrivacy");
                Profile.PrivacyPersonal.Address = pl.NamedPrivacy;
                Profile.Save();
                //SetTopMostMessage("联系方式已经更新。", true);
            }
        }

        void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        {            
            
        }

        void LinqDataSource1_Selected(object sender, LinqDataSourceStatusEventArgs e)
        {
            
        }

        protected void addrPrivacy_Load(object sender, EventArgs e)
        {
            ((PrivacyDropDownList)sender).NamedPrivacy = Profile.PrivacyPersonal.Address;
        }
    }
}
